<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Dcat\Admin\Traits\ModelTree;
use Spatie\EloquentSortable\Sortable;

class WxMenu extends Model implements Sortable
{
    use ModelTree;

    protected $table = 'wx_menu';

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {

        });

        static::created(function ($model) {

        });

        static::updating(function ($model) {
            // 在模型更新之前触发的操作
//            $model->original = $model->getOriginal();
        });

        static::updated(function ($model) {
//            $original = $model->original;
//            $changes = $model->getChanges();
//
//            // 对比更新前后的字段
//            foreach ($changes as $key => $value) {
//                if($key == 'status') {
//                    $originalValue = $original[$key];
//
//                }
//            }
        });

        static::deleting(function ($model) {
            // 在删除之前执行的逻辑
            if($model->id <= 30){
                throw new \Exception('不能删除id小于30的系统内置菜单');
            }
        });

        static::deleted(function ($model) {

        });
    }

}
